package com.ityu.controller;

import com.ityu.pojo.Emp;
import com.ityu.pojo.pagePojo.EmpPage;
import com.ityu.pojo.result.Result;
import com.ityu.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {

    @Autowired
    EmpService empService;

    @GetMapping
    public Result pageListEmp(EmpPage  empPage){
        log.info("-----EmpController-----条件分页查询员工，参数为{}",empPage);
        return  Result.success( empService.pageListEmp(empPage) );
    }


    @DeleteMapping
    public Result deleteEmps(@RequestParam List<Integer> ids){
        log.info("-----EmpController-----批量删除员工，参数为{}",ids);
        empService.deleteEmps(ids);
        return Result.success();
    }

    @PostMapping
    public  Result addEmp(@RequestBody Emp emp){
        log.info("-----EmpController-----添加员工，参数为{}",emp);
        empService.addEmp(emp);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getEmpById( @PathVariable Integer id){
        log.info("-----EmpController-----根据id查询员工，参数为{}",id);
        return Result.success( empService.getEmpById(id) );
    }

    @PutMapping
    public Result updateEmp(@RequestBody Emp emp){
        log.info("-----EmpController-----修改员工，参数为{}",emp);
        empService.updateEmp(emp);
        return Result.success();
    }

    @GetMapping("/list")
    public Result listEmp(){
        log.info("-----EmpController-----查询所有员工");
        return Result.success( empService.listEmp() );
    }

}
